package cn.itxc.demo.service.impl;

import cn.itxc.demo.datasource.TargetDataSource;
import cn.itxc.demo.entity.Test;
import cn.itxc.demo.mapper.TestMapper;
import cn.itxc.demo.service.ITestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Gavin on 2017/6/14.
 */
@Service
public class TestService implements ITestService {

    @Autowired
    TestMapper testMapper;

    @Override
    @TargetDataSource(name = "mysql1")
    public void testDataSource1() {
        List<Test> tests =  testMapper.selectAll();
        tests.forEach(e -> System.out.println(e.getName()));
    }

    @Override
    @TargetDataSource(name = "mysql2")
    public void testDataSource2() {
        List<Test> tests =  testMapper.selectAll();
        tests.forEach(e -> System.out.println(e.getName()));
    }

    @Override
    public void testMainDataSource() {
        List<Test> tests =  testMapper.selectAll();
        tests.forEach(e -> System.out.println(e.getName()));
    }

    @Override
    @TargetDataSource(name = "my")
    public void testUserDataSource() {
        List<Test> tests =  testMapper.selectAll();
        tests.forEach(e -> System.out.println(e.getName()));
    }
}
